package com.team7.controller;

import com.team7.common.entity.Video;
import com.team7.service.VideoService;
import com.team7.vo.CommonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/core/video")
public class VideoController {
    @Resource
    private VideoService videoService;

    @ApiOperation("根据章节id查询课时信息")
    @GetMapping("findAllVideo/{chapterId}")
    public CommonResult findAllVideo(@PathVariable String chapterId){
        return videoService.findAllVideo(chapterId);
    }

    @ApiOperation("新增条课时")
    @PutMapping("insertVideo")
    public CommonResult insertVideo(@RequestBody Video video){
        return videoService.insertVideo(video);
    }

    @ApiOperation("修改课时信息")
    @PostMapping("updateVideo")
    public CommonResult updateVideo(@RequestBody Video video){
        return videoService.updateVideo(video);
    }

    @ApiOperation("根据id删除一条记录，，若删除的是中间的课程，相应减少排序比他大的课程的sort")
    @DeleteMapping("deleteById/{id}/{sort}/{chapterId}")
    public CommonResult deleteById(@PathVariable String id,
                                   @PathVariable Integer sort,
                                   @PathVariable String chapterId
                                   ){
        return videoService.deleteById(id,sort,chapterId);
    }

}